﻿
using Maticsoft.BLL;
using Maticsoft.DBUtility;
using Maticsoft.Model;

using System;
using System.Data;
using System.Text;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Wuqi.Webdiyer;

public partial class WebPage_Index_DuanxinDingyue : SystemBBasePage
{

    private Maticsoft.BLL.Category categoryBll = new Maticsoft.BLL.Category();
    private Maticsoft.Model.Category categoryModel = new Maticsoft.Model.Category();

    private string sql = "1=1 and Enable='Y'  ";
    private int text = Convert.ToInt32(PageIndex.pageIndex);

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        this.getDuanxin();
    }

    private void getDuanxin()
    {
        StringBuilder builder = new StringBuilder();
        StringBuilder builder2 = new StringBuilder();
        builder.Append("<tr >");
        builder.Append("<th width='350'>手机号</td>");
        builder.Append("<th width='80'>城市</td>");
        builder.Append("<th width='350'>密钥</td>");
        builder.Append("<th width='80'>操作</td>");
        builder.Append("</tr>");
        int count = 0;
        DataTable table = DbHelperSQL.GetDataTableByPager(this.text, this.AspNetPager1.CurrentPageIndex, "Id desc", this.sql, "Smssubscribe", out count);
        this.AspNetPager1.RecordCount = count;
        this.AspNetPager1.PageSize = this.text;
        if (table.Rows.Count > 0)
        {
            for (int i = 0; i < table.Rows.Count; i++)
            {
                if ((i % 2) != 0)
                {
                    builder2.Append("<tr>");
                }
                else
                {
                    builder2.Append("<tr class='alt'>");
                }
                builder2.Append("<td>" + table.Rows[i]["Mobile"] + "</td>");
                if ((table.Rows[i]["Id"] != null) && (table.Rows[i]["Id"].ToString() != ""))
                {
                    this.categoryModel = this.categoryBll.GetModel(Convert.ToInt32(table.Rows[i]["City_id"].ToString()));
                    if (this.categoryModel != null)
                    {
                        builder2.Append("<td>" + this.categoryModel.Name + "</td>");
                    }
                    else
                    {
                        builder2.Append("<td>全国</td>");
                    }
                }
                else
                {
                    builder2.Append("<td>全国</td>");
                }
                builder2.Append("<td>" + FormsAuthentication.HashPasswordForStoringInConfigFile(table.Rows[i]["Secret"].ToString(), "md5") + "</td>");
                builder2.Append(string.Concat(new object[] { "<td><a class=\"remove-record\" href='Index_DuanxinDingyue.aspx?remove=", table.Rows[i]["Id"], "&pageIndex=", this.AspNetPager1.CurrentPageIndex, "&where=", DESEncrypt.Encrypt(this.sql, "type"), "' >删除</a></td>" }));
                builder2.Append("</tr>");
            }
        }
        this.Literal1.Text = builder.ToString();
        this.Literal2.Text = builder2.ToString();
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        this.HeaderControl1.Select = "index";
        if (base.Request.QueryString["remove"] != null)
        {
            new Maticsoft.BLL.Smssubscribe().Delete(int.Parse(base.Request.QueryString["remove"].ToString()));
            base.SetSuccess("删除成功");
            if ((base.Request.QueryString["pageIndex"] != null) && (base.Request.QueryString["pageIndex"].ToString() != ""))
            {
                this.AspNetPager1.CurrentPageIndex = Convert.ToInt32(base.Request.QueryString["pageIndex"].ToString());
            }
            if ((base.Request.QueryString["where"] != null) && (base.Request.QueryString["where"].ToString() != ""))
            {
                this.sql = DESEncrypt.Decrypt(base.Request.QueryString["where"].ToString(), "type");
            }
        }
        if (base.Request.HttpMethod == "POST")
        {
            if (this.txtcity.Text != "")
            {
                this.sql = this.sql + " and City_id=" + this.txtcity.Text;
            }
            if (this.txtmobile.Text != "")
            {
                this.sql = this.sql + " and Mobile like '%" + this.txtmobile.Text + "%' ";
            }
        }
        this.getDuanxin();
    }
}


